//
//  QTHomeHeadViewCell.m
//  QTLifeCircle
//
//  Created by 王琼 on 17/1/16.
//  Copyright © 2017年 徐腾. All rights reserved.
//

#import "QTHomeHeadViewCell.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>

@interface QTHomeHeadViewCell()

@property(nonatomic, weak) UIImageView *coverImage;
@property(nonatomic, weak) UILabel * titleLabel;

@end

@implementation QTHomeHeadViewCell


-(instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self setupUI];
    }
    return self;
}



-(void)setupUI
{
    UIImageView* coverImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
    self.backgroundColor = [UIColor whiteColor];
    self.coverImage = coverImage;
    //假数据
    coverImage.image = [UIImage imageNamed:@"no"];
    [self.contentView addSubview:coverImage];
    
    UILabel* titleLabel = [[UILabel alloc]init];
    titleLabel.text = @"名字";
    titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel = titleLabel;
    [self.contentView addSubview:titleLabel];
    
    [coverImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(15);
        make.bottom.equalTo(titleLabel).offset(-15);
        make.size.mas_equalTo(CGSizeMake(60, 60));
     
    }];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(coverImage.mas_bottom).offset(8);

    }];

}

-(void)setModel:(QTHeadItemModel *)model
{
    _model = model;
    //店铺图片地址
    NSURL* URL = [NSURL URLWithString:model.cover];
    
    [self.coverImage sd_setImageWithURL:URL placeholderImage:[UIImage imageNamed:@"no"]];
    
    self.titleLabel.text = model.title;
    if(model.title == nil)
    {
       self.titleLabel.text = @"没请求到数据";
    }
    
}
@end
